﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BruteForce.Screens.PlayingScreen.Map
{
    internal static class Tile
    {
        public static Texture2D TileSetTexture;
        public static Texture2D CastleTexture;

        public static int TileWidth = 64;
        public static int TileHeight = 64;
        public static int TileStepX = 64;
        public static int TileStepY = 16;
        public static int OddRowXOffset = 32;
        public static int HeightTileOffset = 32;
        public static KeyValuePair<Texture2D, Rectangle>[] Textures;

        public static Vector2 OriginPoint = new Vector2(19, 39);

        public static Rectangle GetSourceRectangle(int tileIndex)
        {
            int tileY = tileIndex/(TileSetTexture.Width/TileWidth);
            int tileX = tileIndex%(TileSetTexture.Width/TileWidth);

            return new Rectangle(tileX*TileWidth, tileY*TileHeight, TileWidth, TileHeight);
        }

        public static void CutContent()
        {
            Textures = new KeyValuePair<Texture2D, Rectangle>[100];
            int i = 1;
            int s = -25;
            Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 0 + s, 64, 64));
            Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 32 + s, 64, 64));
            Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 64 + s, 64, 64));
            Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 96 + s, 64, 64));
        }
    }
}